using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Serialization;
using UnityEngine.UI;

public class PlayerController : MonoBehaviour
{
    public float speed = 0.3f;
    public Animator animator;
    private Vector3 movement;

	void Awake()
	{
        animator = GetComponent<Animator>();
        movement = transform.position;

        //SpriteRenderer spr = weapen.GetComponent<SpriteRenderer>();
	}

	void Update()
	{
	}

	void FixedUpdate()
    {
        Move();


        // Vector3 mouse = Input.mousePosition;
        // Vector3 mouseWorld = Camera.main.ScreenToWorldPoint(new Vector3(mouse.x, mouse.y,
        //     transform.position.y));
        // Debug.Log("mouse.X"+mouseWorld.x+" mouse.Y"+mouseWorld.y+" mouse.Z"+mouseWorld.z);
    }

    void Move()
    {
        int horizontal = (int) (Input.GetAxisRaw ("Horizontal"));
        int vertical = (int) (Input.GetAxisRaw ("Vertical"));
        //animation
        Vector3 move = Vector3.zero;
        move.x = horizontal;
        move.y = vertical;
        // if(horizontal > 0)
        //     move.x = horizontal;
        // else if(horizontal < 0)
        //     move.x = -1f;
        // else
        //     move.x = 0;

        // if(vertical > 0 && horizontal == 0)
        //     move.y = 1f;
        // else if(vertical < 0 && horizontal == 0)
        //     move.y = -1f;
        // else
        //     move.y = 0;
        /*
        if(move.sqrMagnitude > 0)
            animator.SetBool("move",true);
        else
            animator.SetBool("move",false);
        
        animator.SetFloat("x",move.x);
        animator.SetFloat("y",move.y);
        */
        //move
        transform.Translate(horizontal*speed, vertical*speed, 0);
        movement = transform.position;
        GetComponent<Rigidbody2D>().MovePosition(movement);
        // player.Rigidbody2D.MovePosition(hatPosition);
    }

}


